package com.tsmti.webservice.entity;


import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.Date;

/**
 * Title：PimsSystem
 * Class：com.tsmti.core.common.entity
 * Comapny:
 *
 * @author：zcw
 * @version：2.5 CreateTime：2018/1/16 11:19
 * Modify log:
 * Description：
 */
@DynamicInsert
@DynamicUpdate
@MappedSuperclass
public abstract class BaseDataEntity<PK extends Serializable> extends AbstractEntity<PK>  implements MarkDeleteable,Serializable {

    private static final long serialVersionUID = 3055843173261717948L;

    protected static final Integer DEL_FLAG_NORMAL = 0;
    protected static final Integer DEL_FLAG_DELETE = 1;

    protected Boolean isDelete = Boolean.TRUE;

    /**删除标记（0：正常；1：删除 ）*/
    protected Integer delFlag = DEL_FLAG_NORMAL;
    /*** 创建者*/
    protected String createUser;
    /*** 创建日期*/
    protected Date createDate;
    /*** 更新者*/
    protected String updateUser;
    /*** 更新日期*/
    protected Date updateDate;
    /**机构ID*/
    protected String orgId;

    @Override
    public Integer getDelFlag() {
        return delFlag;
    }

    @Override
    public void setDelFlag(Integer delFlag) {
        this.delFlag = delFlag;
    }


    public String getCreateUser() {
        return createUser;
    }

    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getUpdateUser() {
        return updateUser;
    }

    public void setUpdateUser(String updateUser) {
        this.updateUser = updateUser;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public String getOrgId() {
        return orgId;
    }

    public void setOrgId(String orgId) {
        this.orgId = orgId;
    }
    /**
     * 这表数据是否需要标记删除
     *
     * @param isDelete
     */
    @Transient
    @Override
    public void markDelete(Boolean isDelete) {
        if (this.isDelete) {
            delFlag = DEL_FLAG_DELETE;
        } else {
            delFlag = DEL_FLAG_NORMAL;
        }
    }

    @Transient
    @Override
    public Boolean markStatus() {
        if (this.isDelete) {
            delFlag = DEL_FLAG_DELETE;
        } else {
            delFlag = DEL_FLAG_NORMAL;
        }
        return this.isDelete;
    }

    @Override
    public String toString() {
        return ReflectionToStringBuilder.toString(this);
    }

}
